<template>
<div class="migration views-container">
  <div class="main">
    <div class="pos-center">
      <div class="flex-col flex-align-c">
        <el-button type="primary" class="main-bottom20" @click="movedata">数据迁移</el-button>
        <!-- <p class="main-bottom10">输入源站点根目录</p>
        <el-input class="main-bottom20" v-model="source" placeholder="输入源站点根目录"></el-input>
        <el-progress v-if="showPercentage&&$percentage>0" style="margin:30px 0;width:100%;height:30px;" :text-inside="true" :stroke-width="26" :percentage="parseInt($percentage*100)/100"></el-progress>
        <el-button class="main-bottom20" type="primary" @click="movefile">确认文件迁移</el-button> -->
      </div>
    </div>
  </div>
</div>
</template>

<script>
import {
  dataMigration,
  filesMigration,
  beginFileMigration
} from '@/api/cloudservice'
export default {
  name: 'Migration',
  components: {

  },
  computed: {
    $percentage() {
      let num = (Number(this.nowUpdateFile) / Number(this.allUpdateFile)) * 100
      num = num.toFixed(2)
      // num=parseInt(num*100)/100;
      if (num > 100) {
        num = 100
      }
      this.$forceUpdate()
      return num
    },
    $oppo() {
      return '0.20'
    }
  },
  data() {
    return {
      source: '',
      showPercentage: false,
      nowUpdateFile: 0,
      allUpdateFile: 0
    }
  },
  created() {
    this.$nextTick(() => {
    //   this.timeCreate()
    })
  },
  methods: {
    movedata() {
      dataMigration().then((response) => {
        const res = response.data
        if (res.code === 1) {
          this.$message.success(res.message || '数据迁移成功')
        }
      })
    },
    movefile() {
      filesMigration({ source: this.source }).then((response) => {
        const res = response.data
        if (res.code === 1) {
          // this.$message.success(res.message || '文件迁移准备完成')
          this.allUpdateFile = res.data
          this.setpB()
        }
      })
    },
    setpB() {
      beginFileMigration().then((res) => {
        const { data: { data } } = res
        this.nowUpdateFile = this.nowUpdateFile + 1
        console.log(this.nowUpdateFile, 'this.nowUpdateFile')
        if (data) {
          this.setpB()
          this.showPercentage = true
        } else {
          this.$message.success(res.message || '文件迁移成功')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.migration {
  font-size: 14px;

  .main {
    width: 100%;
    min-height: calc(100vh - 90px);
    border-radius: 4px;
    background: #ffffff;
  }

  .main-bottom20 {
    margin-bottom: 20px;
  }
  .main-bottom10 {
    margin-bottom: 10px;
  }
}
</style>
